package com.otupia.blog.context;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class BeanPoolSpringImpl implements BeanPool
{
	private static BeanPoolSpringImpl _pool = new BeanPoolSpringImpl();
	private ApplicationContext springContext = null;

	private static final String SPRING_CONFIG_FILE = "classpath*:otupia_application_blogContext.xml";

	private BeanPoolSpringImpl()
	{
		ApplicationContext ctx = new FileSystemXmlApplicationContext(BeanPoolSpringImpl.SPRING_CONFIG_FILE);
		this.springContext = ctx;
	}

	public static BeanPool getInstance()
	{
		return BeanPoolSpringImpl._pool;
	}

	@Override
	public <T> T getBean(Class<T> clazz)
	{
		return this.getBean(clazz.getName(), clazz);
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> T getBean(String name, Class<T> clazz)
	{
		return (T) this.springContext.getBean(name, clazz);
	}

	@Override
	public Object getBean(String name)
	{
		return this.springContext.getBean(name);
	}
	
	public static void main(String[] args)
	{
		BeanPool test = BeanPoolSpringImpl.getInstance();
	}

}
